package com.fuxi;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class student_data {
   Scanner sc =new Scanner(System.in);
   student f=new student();

   List<student> list=  new ArrayList<>();
   public void  stady(){
      System.out.println("请选择如下操作：1-3");
      System.out.println("1.添加学生");
      System.out.println("2.修改学生");
      System.out.println("3.删除学生");
      System.out.println("4.显示学生");
      System.out.println("5.关闭");
      int flag = sc.nextInt();
      switch (flag){
         case 1 :
              studentadd();

         case 2 :
            studentset();

         case 3 :
            studentremove(list);
         case 4:
             on();
         case 5 :
            break;


      }
   }

   private void on() {
      for (int i = 0; i < list.size(); i++) {
         System.out.println(list.get(i));
      }
      stady();
   }




   private void studentset() {
      System.out.println("2.修改学生");
      System.out.println("请输入需要配对的对象姓名：");
      String next = sc.next();


      for (int i = 0; i < list.size(); i++) {
         student s = list.get(i);
         if(s.getName().equals(next)){
            System.out.println("请输入学生的名称");
            String name = sc.next();
            s.setName(name);

            break;
         }else {
            System.out.println("wodefa");
         }
         stady();

      }
   }

   public static void studentremove(List<student> list) {
      System.out.println("3.删除学生");
      System.out.println("请输入需要配对的对象姓名：");
      Scanner sc=new Scanner(System.in);
      String next = sc.next();
      for (int i = 0; i < list.size(); i++) {
         if (list.get(i).getName().equals(next)){
            list.remove(i);
          break;
         }

      }
   }

   private void studentadd() {
      System.out.println("1.添加学生");
      for (int i = 0; i < 3; i++) {
         System.out.println("请输入学生名字：");
         String sname = sc.next();
         System.out.println("请输入学生id：");
         int  sid =  sc.nextInt();

         student f = new student();
         f.setName(sname);
         f.setId(sid);
         list.add(f);
      }

      for (int i = 0; i < list.size(); i++) {
        String s = list.get(i).toString();
         System.out.println(s);
      }
      stady();
   }
}
